<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: absolute;
            left: 0;
            top: 80px;
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div></div>
    <hr>
    <button class="btn">走</button>
    <script>
        function animate(obj, target, callback) {
            clearInterval(obj.timer)
            obj.timer = setInterval(function() {
                var step = (target - obj.offsetLeft) / 10
                step = step > 0 ? Math.ceil(step) : Math.floor(step)
                if (obj.offsetLeft == target) {
                    callback && callback();
                    return clearInterval(obj.timer)
                } else {

                    obj.style.left = obj.offsetLeft + step + 'px'
                }
            }, 15)
        }
        var div = document.querySelector('div')
        var btn = document.querySelector('.btn')
        btn.onclick = function() {
            animate(div, 800, function() {
                alert('出来吧神奇宝贝')
            })
        }
    </script>
</body>

</html>